const util = require('../../../utils/util.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    showNum: 6,
    list: [],
    idx: 0,
    bottom: 0,
    showplayBtn: false,
    current: 0,
    showList: false,
    forlist: [],
    imgUrl: getApp().globalData.imgUrl,
    imgUrls: getApp().globalData.imgUrls,
    videoArr: [{
      img: 'https://o6wndwjxn.qnssl.com/woshinibabnormal%20video.mp4',
      play: false
    }, {
      img: 'http://o6wndwjxn.qnssl.com/1554282701530701277142.mp4',
      play: false
    }, ]
  },
 

  /**
   * 生命周期函数--监听页面加载
   */
  // getBottomValue(e) {
  //   this.setData({
  //     bottom: parseInt(e.detail.dy),
  //     bottom1: Math.abs(this.data.bottom)
  //   })
  // },
  bindprogress(event){
    this.setData({
      buffered:event.detail.buffered
    })
  },
  binderror(e){
    var videoArr=  this.data.videoArr
    videoArr.splice(e.currentTarget.dataset.index, 1)
this.setData({
  videoArr
})
  },
  getIdx(e) {
    this.setData({
      idx: e.detail.current,
    })
    this.data.pageNum=1
    this.data.list=[]
    var query = wx.createSelectorQuery();
    query.select('#myVideo').boundingClientRect(function (rect) {
      // that.setData({
      //   bili: rect.width / rect.height
      // })
    }).exec();

     this.dantiao()
  },
  onLoad: function(options) {
    console.log(options.jump_id)
    var that = this
    this.setData({
      windowHeight: wx.getSystemInfoSync().windowHeight
    })
    if (options.jump_id != 'undefined') {
      options.id = options.jump_id;
      options.flag='0'
    }
    util.API('spwx/v1.shop/video_list', {
      pageshow: 100000000000,
      flag: options.flag
    }).then(res => {
      let {
        code,
        data
      } = res
     
      var idx = data.allowLook.findIndex(item => item.video_id == options.id);
      idx = idx > -1 ? idx :0;
      var query = wx.createSelectorQuery();
      query.select('#myVideo').boundingClientRect(function (rect) {
       
      }).exec();
      this.setData({
        idx,
        videoArr: data.allowLook
      })
      this.data.pageNum=1
        this.dantiao()
    })
  },




  onReady: function() {

  },
  close() {
    this.setData({
      showList: false
    })
  },
  showList() {
    this.setData({
      showList: !this.data.showList
    })

  },
  dantiao() {
    util.API('spwx/v1.shop/video_data', {
      pageshow:10,
      page: this.data.pageNum,
      video_id: this.data.videoArr[this.data.idx].video_id,
      type: "wx"
    }).then(res => {
      let {
        code,
        data
      } = res
      if (code == 200) {
        data.click = data.click.length >= 5 ? (data.click / 10000) + "w" : data.click
        data.browse = data.browse.length >= 5 ? (data.browse / 10000) + "w" : data.browse
        if (data.commodity_name.length!=0){
          this.data.list = this.data.list.concat(data.commodity_name.list);
        }
        this.setData({
          list: this.data.list,
          forlistdata: data,
        })
      } else {
        that.setData({
          loading: true,
        })
      }
    
    })
  },
  bindscrolltolower(){
    this.data.pageNum++
    this.dantiao()
  },
  dianzan() {
    util.API('spwx/v1.shop/like_video', {
      video_id: this.data.videoArr[this.data.idx].video_id,
    }).then(res => {
      let {
        code,
        data
      } = res
      var forlistdata= 'forlistdata.click'
      this.setData({
        [forlistdata]: this.data.forlistdata.click + 1
      })
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {},
  /**
   * 生命周期函数--监听页面卸载
   */
  bindtap() {
    wx.createVideoContext('myVideo').pause();
  },
  bindplay() {
    this.setData({
      showplayBtn: false
    })
  },
  playBtn() {
    wx.createVideoContext('myVideo').play();
  },
  bindpause() {
    this.setData({
      showplayBtn: true
    })
  },

})